<script setup lang="ts">
import type {TabsPaneContext} from "element-plus";
import {Search} from "@element-plus/icons-vue";
import {useIndexStore} from "~/store";
import PcDialogAddUser from "~/Components/pc/main/pc-dialog-addUser.vue";
import PcDialogAddGroup from "~/Components/pc/main/pc-dialog-addGroup.vue";

const indexStore = useIndexStore()

const dialogVisible = ref(false)
const handleClose = () => {
  dialogVisible.value = false
}


const activeName = ref('first')
const handleClick = (tab: TabsPaneContext, event: Event) => {
  console.log(tab, event)
}


</script>

<template>
  <div @click="dialogVisible = true">
    添加好友/群聊
  </div>
  <el-dialog
      v-model="dialogVisible"
      width="700"
      :before-close="handleClose"
      :append-to-body="true"
  >
    <template #header>
      <div class="text-center">
        添加好友或群聊
      </div>
    </template>
    <div>
      <div class="p-1">
        <el-input
            v-model="indexStore.search"
            placeholder="输入关键词"
            :prefix-icon="Search"
        />
      </div>
      <el-tabs v-model="activeName" class="demo-tabs p-1" @tab-click="handleClick">
        <el-tab-pane label="全部" name="first">
          <div v-if="indexStore.search_user.length > 0">
            <div class="p-2 text-xl">用户</div>
            <div class="w-full flex *:flex-1">
              <div class="flex" v-for="user in indexStore.search_user">
                <el-avatar :size="50" src="/cover.jpg"/>
                <div class="flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ user.name }}</div>
                  <div>{{ user.account }}</div>
                </div>
                <div class="flex justify-center items-center">
                  <pc-dialog-add-user :add_user="user"/>
                </div>
              </div>
            </div>
          </div>
          <div v-if="indexStore.search_group.length > 0">
            <div class="p-2 text-xl">群聊</div>
            <div class="w-full flex *:flex-1">
              <div class="flex" v-for="group in indexStore.search_group">
                <el-avatar :size="50" :src="group.avater"/>
                <div class="flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ group.name }}</div>
                  <div>{{ group.account }}</div>
                </div>
                <div class="flex justify-center items-center">
                  <pc-dialog-add-group :add_group="group"/>
                </div>
              </div>
            </div>
          </div>
          <el-empty v-else description="输入关键词搜索" />
        </el-tab-pane>
        <el-tab-pane label="好友" name="second">
          <div v-if="indexStore.search_user.length > 0">
            <div class="w-full flex *:flex-1">
              <div class="flex" v-for="user in indexStore.search_user">
                <el-avatar :size="50" src="/cover.jpg"/>
                <div class="flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ user.name }}</div>
                  <div>{{ user.account }}</div>
                </div>
                <div class="flex justify-center items-center">
                  <pc-dialog-add-user :add_user="user"/>
                </div>
              </div>
            </div>
          </div>
          <el-empty v-else description="输入关键词搜索" />
        </el-tab-pane>
        <el-tab-pane label="群聊" name="third">
          <div v-if="indexStore.search_group.length > 0">
            <div class="w-full flex *:flex-1">
              <div class="flex" v-for="group in indexStore.search_group">
                <el-avatar :size="50" :src="group.avater"/>
                <div class="flex *:w-full flex-wrap ml-2 text-[12px] items-center">
                  <div>{{ group.name }}</div>
                  <div>{{ group.account }}</div>
                </div>
                <div class="flex justify-center items-center">
                  <pc-dialog-add-group :add_group="group"/>
                </div>
              </div>
            </div>
          </div>
          <el-empty v-else description="输入关键词搜索" />
        </el-tab-pane>
      </el-tabs>
    </div>
  </el-dialog>
</template>

<style scoped>

</style>